import { getUserDepID, getCompanyID, getUserID } from '@/utils';

/**  领用 Manage数据范围权限判断 */
export const ApplyManageTab = (curRes: Record<string, any>) => {
  if (curRes?.['/assetApplyUes/createCompanyID']) {
    return {
      createCompanyID: getCompanyID(),
      params: 'createCompanyID',
    };
  } else if (curRes?.['/assetApplyUes/createDepartmentID']) {
    return {
      createDepartmentID: getUserDepID(),
      params: 'createDepartmentID',
    };
  } else if (curRes?.['/assetApplyUes/createrID']) {
    return {
      createrID: getUserID(),
      params: 'createrID',
    };
  } else {
    return {};
  }
};

/**
 * 获取 资产/材料 数据 的数据范围权限判断
 * queryType 1:领用 2:退库 3:借用 4:归还
 * type 0:材料  1:资产
 * */
export const AssetMaterialManage = (curRes: Record<string, any>, queryType: string, type: number) => {
  /**
   * 第一层判断是领用(借用)还是退库(归还)
   * 第二层判断是材料还是资产
   * */
  if (queryType == '1' || queryType == '3') {
    // 领用/借用
    if (type == 1) {
      // 如果是资产弹窗
      if (curRes?.['/useAssetMaterial/assetCompanyID']) {
        return {
          assetCompanyID: getCompanyID(),
          params: 'assetCompanyID',
        };
      } else if (curRes?.['/useAssetMaterial/assetDepartmentID']) {
        return {
          assetDepartmentID: getUserDepID(),
          params: 'assetDepartmentID',
        };
      } else {
        return {};
      }
    } else if (type == 0) {
      if (curRes?.['/assetMaterial/assetCompanyID']) {
        return {
          assetCompanyID: getCompanyID(),
          params: 'assetCompanyID',
        };
      } else if (curRes?.['/assetMaterial/assetDepartmentID']) {
        return {
          assetDepartmentID: getUserDepID(),
          params: 'assetDepartmentID',
        };
      } else {
        return {};
      }
    } else {
      return {};
    }
  } else {
    // 退库/归还
    if (type == 1) {
      // 如果是资产弹窗
      if (curRes?.['/assetController/return/useCompanyID']) {
        return {
          useCompanyID: getCompanyID(),
          params: 'useCompanyID',
        };
      } else if (curRes?.['/assetController/return/useDepartmentID']) {
        return {
          useDepartmentID: getUserDepID(),
          params: 'useDepartmentID',
        };
      } else if (curRes?.['/assetController/return/userID']) {
        return {
          userID: getUserID(),
          params: 'userID',
        };
      } else {
        return {};
      }
    } else if (type == 0) {
      if (curRes?.['/assetMaterial/assetCompanyID']) {
        return {
          assetCompanyID: getCompanyID(),
          params: 'assetCompanyID',
        };
      } else if (curRes?.['/assetMaterial/assetDepartmentID']) {
        return {
          assetDepartmentID: getUserDepID(),
          params: 'assetDepartmentID',
        };
      } else {
        return {};
      }
    } else {
      return {};
    }
  }
};

/** 资产领用数据范围权限判断 */
export const AssetEditManage = (curRes: Record<string, any>) => {
  if (curRes?.['/useAssetMaterial/assetCompanyID']) {
    return {
      assetCompanyID: getCompanyID(),
      params: 'assetCompanyID',
    };
  } else if (curRes?.['/useAssetMaterial/assetDepartmentID']) {
    return {
      assetDepartmentID: getUserDepID(),
      params: 'assetDepartmentID',
    };
  } else {
    return {};
  }
};

/** 我的资产Manage数据范围权限判断 */
export const MyAssetListManageTab = (curRes: Record<string, any>) => {
  if (curRes?.['/assetController/userID']) {
    return {
      userID: getUserID(),
      params: 'userID',
    };
  } else {
    return {};
  }
};

/**
 * 预警管理
 * @param curRes
 * @returns
 */
export const getManageTabSwitch = (curRes: Record<string, any>) => {
  if (curRes?.['/assetStore/createCompanyID']) {
    return {
      createCompanyID: getCompanyID(),
      params: 'createCompanyID',
    };
  } else {
    return {
      storeCompanyID: getCompanyID(),
      params: 'storeCompanyID',
    };
  }
};
